package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;

import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.pojo.ApUser;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmSensitiveDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import com.heima.wemedia.service.WmSensitiveService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WemediaClient implements IWemediaClient {

    private final WmUserService wmUserService;

    @Autowired
    private WmChannelService wmChannelService;

    public WemediaClient(WmUserService wmUserService) {
        this.wmUserService = wmUserService;
    }

    @PostMapping("/api/v1/wemedia/add")
    public ResponseResult addWmUser(@RequestBody ApUser apUser) {
        return wmUserService.addWmUser(apUser);
    }

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章审核表
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/wemedia/list_vo")
    @Override
    public PageResponseResult mediaReviewList(@RequestBody NewsAuthDto dto) {
        return wmNewsService.findArticleList(dto);
    }

    /**
     * 媒体审核之查看文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/api/v1/wemedia/detail/{id}")
    @Override
    public ResponseResult mediaDetail(@PathVariable Integer id) {
        return wmNewsService.findDetailById(id);
    }

    /**
     * 人工审核之拒绝
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult mediaAuthFail(NewsAuthDto dto) {
        return wmNewsService.authFail(dto);
    }

    /**
     * 人工审核之通过
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult mediaAuthPass(NewsAuthDto dto) {
        return wmNewsService.authPass(dto);
    }

    /**
     * 删除频道（feign接口提供）
     * @param id
     * @return
     */
    @Override
    @GetMapping("/api/v1/channel/del/{id}")
    public ResponseResult deleteChannel(Integer id) {
        return wmChannelService.deleteChannel(id);
    }

    /**
     * 频道名称模糊分页查询（feign接口提供）
     * @param channelDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/channel/list")
    public PageResponseResult getChannelList(ChannelDto channelDto) {
        return wmChannelService.getChannelList(channelDto);
    }

    /**
     * 保存频道（feign接口提供）
     * @param wmChannel
     * @return
     */
    @Override
    @PostMapping("/api/v1/channel/save")
    public ResponseResult saveChannel(WmChannel wmChannel) {
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 修改频道（feign接口提供）
     * @param wmChannel
     * @return
     */
    @Override
    @PostMapping("/api/v1/channel/update")
    public ResponseResult updateChannel(WmChannel wmChannel) {
        return wmChannelService.updateChannel(wmChannel);
    }

    @Autowired
    private WmSensitiveService wmSensitiveService;
    @Override
    @DeleteMapping("/api/v1/sensitive/feign/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {

        return wmSensitiveService.deleteById(id);
    }

    @Override
    @PostMapping("/api/v1/sensitive/feign/list")
    public ResponseResult list(WmSensitiveDto dto) {

        return wmSensitiveService.list(dto);
    }

    @Override
    @PostMapping("/api/v1/sensitive/feign/save")
    public ResponseResult sensitiveSave(WmSensitiveDto dto) {

        return wmSensitiveService.sensitiveSave(dto);
    }

    @Override
    @PostMapping("/api/v1/sensitive/feign/update")
    public ResponseResult update(WmSensitiveDto dto) {

        return wmSensitiveService.update(dto);
    }
}
